package linklist;

//删除链表的倒数第n个节点
public class LeetCode_21 {
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode head1 = list1,head2 = list2;
        ListNode head = new ListNode(),result = head;
        while (head1!=null && head2!=null){
            ListNode tempNode1 = head1,tempNode2 = head2;
            if (head1.val<=head2.val){
                head.next = head1;
                head1=head1.next;
            }else {
                head.next = head2;
                head2 =head2.next;
            }
            head = head.next;
        }
        if (head1!=null){
            head.next = head1;
        } else {
            head.next = head2;
        }
        return result.next;
    }



}
